import 'package:sqflite/sqflite.dart';
import 'package:todo_project/data/task_data.dart';
import 'package:todo_project/database/db_helper.dart';

class TaskDB {
  late Database db;

  void insertTask(TaskData task) async {
    await db.insert("task", task.toMap());
  }

  void taskStatusChange(TaskData task) async {
    await db.update("task", task.toMap(),
        where: "${TaskTableColumn.id} = ", whereArgs: [task.id]);
  }

  void taskRemove(TaskData task) async {
    db.delete("task", where: "${TaskTableColumn.id} = ", whereArgs: [task.id]);
  }

  void _createDataBaseTable() async {
    db = await DBHelper.openDB(open: (db) {
      db.execute(
          "CREATE TABLE task (${TaskTableColumn.id} INTEGER PRIMARY KEY,${TaskTableColumn.taskName} TEXT"
          ",${TaskTableColumn.updateTime} DATE,${TaskTableColumn.complete} INTEGER,${TaskTableColumn.createTime} DATE)");
    });
  }

  void queryTaskList() {}

  void selectTaskInfo() {}

  void deleteAllData() {}
}

class TaskTableColumn {
  static const String id = "id";
  static const String taskName = "tas_name";
  static const String updateTime = "update_time";
  static const String createTime = "create_time";
  static const String complete = "complete";
}
